<template>
  <div>
    <!-- 面包屑-->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>权限管理</el-breadcrumb-item>
      <el-breadcrumb-item>角色列表</el-breadcrumb-item>
    </el-breadcrumb>

    <!--    卡片视图-->
    <el-card class="box-card">
      <el-button type="primary">添加角色</el-button>
      <el-table :data="rolesList" border stripe>
        <el-table-column type="expand">
          <template slot-scope="scope">
            <el-row v-for="(item1,index1) in scope.row.children"
                    :class="['border-bottom-solid',index1===0?'border-top-solid':'']">
              <el-col :span="8">
                <el-tag :key="item1.id" closable>{{item1.authName}}</el-tag>
              </el-col>
              <el-col :span="16">
                <el-row v-for="(item2,index2) in item1.children"
                        :class="['border-bottom-solid',index1===0?'border-top-solid':'']">
                  <el-col :span="8">
                    <el-tag :key="item2.id" type="success" closable>{{item2.authName}}</el-tag>
                  </el-col>
                  <el-col :span="16">
                    <el-tag :key="item3.id" type="warning" v-for="(item3,index3) in item2.children" closable>
                      {{item3.authName}}
                    </el-tag>
                  </el-col>
                </el-row>
              </el-col>
            </el-row>
          </template>
        </el-table-column>
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column label="角色名称" prop="roleName"></el-table-column>
        <el-table-column label="角色描述" prop="roleDesc"></el-table-column>
        <el-table-column label="操作" width="300px">
          <template slot-scope="scope">
            <el-button size="mini" type="primary" icon="el-icon-edit">编辑</el-button>
            <el-button size="mini" type="danger" icon="el-icon-delete">删除</el-button>
            <el-button size="mini" type="warning" icon="el-icon-setting" @click="showSetRightDialog">分配权限</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>

    <!--    分配权限对话框-->
    <el-dialog
      title="权限分配"
      :visible.sync="dialogVisible"
      width="50%">
      <!--      树形控件-->
      <el-tree :data="rightsList" :props="treeProps" show-checkbox @node-click="" node-key="id" default-expand-all></el-tree>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>

  </div>
</template>

<script>
  import {getRolesList, getRightTree} from '../../network/home'

  export default {
    name: "Roles",
    data() {
      return {
        rolesList: [],
        dialogVisible: false,
        rightsList: [],
        treeProps:{
          label:'authName',
          children:'children'
        }
      }
    },
    methods: {
      showSetRightDialog() {
        getRightTree().then(res => {
          console.log(res);
          if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
          this.rightsList = res.data
        })
        this.dialogVisible = true
      }
    },
    created() {
      //获取列表数据
      getRolesList().then(res => {
        console.log(res);
        if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
        this.rolesList = res.data
      })
    }
  }
</script>

<style scoped>
  .el-col {
    align-items: center;
  }

  .el-tag {
    box-sizing: border-box;
    height: 32px;
    line-height: 30px;
    margin: 9px;
  }

  .border-top-solid {
    border-top: 1px solid #eee;
  }

  .border-bottom-solid {
    border-bottom: 1px solid #eee;
  }
</style>
